<template>
	<view>
		<view v-if="user.blacklistStatus == 1" style="color: #fff;font-size: 24rpx;padding: 30rpx;background: #aaa;">司机已被{{ etpName }}列入黑名单。</view>
		<view v-else>
			<view v-if="user.status == 1" style="color: #fff;font-size: 24rpx;padding: 30rpx;background: #41ef6c;">司机信息已提交给 {{ etpName }}审核，请耐心等待。</view>
			<view v-if="user.status == 2 && statusText == '已认证'" style="color: #fff;font-size: 24rpx;padding: 30rpx;background: #4275ef;display: flex;justify-content: center;align-items: center;"><image src="../../static/icon_pass.png" mode="" style="width: 40rpx;height: 40rpx;"></image>司机信息已成功认证！</view>
			<view v-if="user.status == 2 && statusText == '已过期'" style="color: #fff;font-size: 24rpx;padding: 30rpx;background: #4275ef;" @click="onresve(1)">证件已过期，请重新上传。点击 <text style="color: red;text-decoration:underline;">立即修改</text></view>
			<view v-if="user.status == 3" style="color: #fff;font-size: 24rpx;padding: 30rpx;background: #FB8536;" @click="onresve(2)">
				司机信息被驳回，原因： {{ user.reject }}，请在此处点击<text style="color: red;text-decoration:underline;">立即修改</text>
			</view>
			<view v-if="user.status == 4" style="color: #fff;font-size: 24rpx;padding: 30rpx;background: #41ef6c;">司机信息存在异常，已提交给平台申诉，申诉过程中可以正常接单。</view>
		</view>
		<view class="body">
			<view class="item">
				<view class="column-css view-cente">
					<view class="row-css view-cente-cle">
						<view class="view-cente-cle-text">姓名</view>
						<view style="padding-right: 30rpx;">{{ user.driverName }}</view>
					</view>
				</view>
				<view class="column-css view-cente">
					<view class="row-css view-cente-cle" style="justify-content: space-between;align-items: center;" @click="onupdatph">
						<view class="row-css" style="flex: 1;justify-content: space-between;">
							<view class="view-cente-cle-text">手机号</view>
							<view>{{ user.mobile }}</view>
						</view>
						<image style="width: 28rpx;height: 28rpx;" src="../../static/icon_enter.png"></image>
					</view>
				</view>
				<view class="column-css view-cente">
					<view class="row-css view-cente-cle">
						<view class="view-cente-cle-text">身份证号</view>
						<view style="padding-right: 30rpx;">{{ user.idcard }}</view>
					</view>
				</view>
				<view class="column-css view-cente">
					<view class="row-css view-cente-cle">
						<view class="view-cente-cle-text">身份证有效期</view>
						<view style="padding-right: 30rpx;">{{ formatDate(user.idcardStartDate) }}-{{ formatDate(user.idcardEndDate) }}</view>
					</view>
				</view>
				<view class="column-css view-cente">
					<view class="row-css view-cente-cle">
						<view class="view-cente-cle-text">驾驶证有效期</view>
						<view style="padding-right: 30rpx;">{{ formatDate(user.driverStartDate) }}-{{ formatDate(user.driverEndDate) }}</view>
					</view>
				</view>
				<view class="column-css view-cente">
					<view class="row-css view-cente-cle" style="justify-content: space-between;align-items: center;border-bottom: none" @click="persondocuments()">
						<view class="row-css" style="flex: 1;justify-content: space-between;">
							<view class="view-cente-cle-text">证件管理</view>
							<view class="perfection" :style="{ color: statusText == '已过期' ? '#E04B28' : '#333' }">{{statusText}}</view>
						</view>
						<image style="width: 28rpx;height: 28rpx;" src="../../static/icon_enter.png"></image>
					</view>
				</view>
			</view>
			<view class="item">
				<view class="column-css view-cente">
					<view class="row-css view-cente-cle" style="justify-content: space-between;align-items: center;border-bottom: none;" @click="shake">
						<view class="row-css" style="flex: 1;justify-content: space-between;">
							<view class="view-cente-cle-text">活体认证</view>
							<view :style="{ color: user.livingBodyState == '0' ? '#DD524D' : '#000000' }">{{ islivingcertifi }}</view>
						</view>
						<image style="width: 28rpx;height: 28rpx;" src="../../static/icon_enter.png"></image>
					</view>
				</view>
			</view>
			<view class="item">
				<view class="column-css view-cente">
					<view class="row-css view-cente-cle" style="justify-content: space-between;align-items: center;border-bottom: none;" @click="shake">
						<view class="row-css" style="flex: 1;justify-content: space-between;" >
							<view class="view-cente-cle-text">服务评分：</view>
							
							<uni-rate allow-half :value="user.driverScore" :size="24" :readonly="true"/>
							<view class="jumpCss" @click.stop="jumpRate()"></view>
						</view>
						<image style="width: 28rpx;height: 28rpx;" src="../../static/icon_enter.png" @click="jumpRate()"></image>
					</view>
				</view>
			</view>
			
		</view>
		<!-- <view class="column-css view-cente">
			<view v-if="user.isLocation == 0" class="row-css view-cente-cle" style="justify-content: space-between;align-items: center;" @click="ontoauthorize">
				<view class="row-css" style="flex: 1;justify-content: space-between;">
					<view class="view-cente-cle-text">基站定位授权</view>
					<view>未授权</view>
				</view>
				<image style="width: 28rpx;height: 28rpx;" src="../../static/icon_enter.png"></image>
			</view>
			<view v-else class="row-css" style="justify-content: space-between;align-items: center;" @click="ontoauthorize">
				<view class="row-css view-cente-cle" style="flex: 1;justify-content: space-between;">
					<view class="view-cente-cle-text">基站定位授权</view>
					<view>已授权</view>
				</view>
				<image style="width: 28rpx;height: 28rpx;" src="../../static/icon_enter.png"></image>
			</view>
		</view> -->
		
		<view class="position-fixed" @click="onLoginout()">退出登录</view>
		<view class="row-css" style="width: 100%; position: fixed;font-size: 24rpx;bottom: 0; margin-bottom: 20rpx;justify-content: center;">
			<text style="color: #7A7A7A;" @click="onproctocl(1)">《服务协议》</text>
			与
			<text style="color: #7A7A7A;" @click="onproctocl(2)">《隐私政策》</text>
		</view>
	</view>
</template>

<script>
import uniRate from '@/components/uni-rate/uni-rate.vue';
export default {
	components: {
		uniRate
	},
	data() {
		return {
			etpName: uni.getStorageSync(this.DATA_KEY.etpName),
			statusText: '',
			user: {},
			islivingcertifi: '未认证',
			timer: null,
			
			orderNumber: null,
			accessToken: null,
			platformCoId: uni.getStorageSync(this.DATA_KEY.platformCoNo) == '0001' ? '100001' : '100002',
			flag: false,
			rateValue: 0.0,
			count: 5
		};
	},
	methods: {
		textStatus() {
			if(this.user.isRealname == 0){
				this.statusText = '未实名'
			}else{
				if(this.user.infoState == 0){
					if(this.user.blacklistStatus == 1){
						this.statusText = '黑名单'
					}else{
						if(this.user.status == 1){
							// this.statusText = '审核中'
							this.statusText = '待认证'
						}
						if(this.user.status == 2){
							let driverEndDate = Date.parse(this.user.driverEndDate) + 24*60*60*1000
							let idcardEndDate = Date.parse(this.user.idcardEndDate) + 24*60*60*1000
							// let driverEndDate = new Date(this.user.driverEndDate)
							// let idcardEndDate = new Date(this.user.idcardEndDate)
							let currentDate = Date.now()
							// let currentDate = new Date().getTime()
							if (currentDate > idcardEndDate || currentDate > driverEndDate) {
								this.statusText = '已过期'
							} else {
								this.statusText = '已认证'
							}
						}
						if(this.user.status == 3){
							this.statusText = '已驳回'
						}
						if(this.user.status == 4){
							this.statusText = '申诉中'
						}
					}
				}else{
					let driverEndDate = new Date(this.user.driverEndDate)
					let idcardEndDate = new Date(this.user.idcardEndDate)
					let currentDate = new Date()
					if(this.user.blacklistStatus == 1){
						this.statusText = '黑名单'
					} else {
						if(currentDate > idcardEndDate || currentDate > driverEndDate) {
							this.statusText = '已过期'
						} else {
							this.statusText = '已认证'
						}
					}
				}
			}
			
		},
		jumpRate(){
			uni.navigateTo({
				url: `../personal/rate`
			});
		},
		formatDate (validPeriod) {
			let reg = new RegExp("\\d{4}(-|/|.)\\d{2}(-|/|.)\\d{2}");
			let test = reg.test(validPeriod);
			if (!test) {
				return "";
			} else {
				return validPeriod.match(reg)[0]
			}
		},
		
		ontoauthorize() {
			if (this.user.isLocation == 0) {
				uni.navigateTo({
					url: `../personal/locationauthorization`
				});
			} else {
				if (this.user.operatorType == 'unicom') {
					uni.navigateTo({
						url: `../personal/canpowerattorney`
					});
				} else {
					uni.navigateTo({
						url: `../personal/cancelauthorize`
					});
				}
			}
		},
		onLoginout() {
			this.wxRequest({
				url: `${this.API}/miniApp/auth/wxLogout`,
				method: 'POST',
				title: '加载中...',
				success: res => {
					uni.setStorageSync(this.DATA_KEY.userInfo, '');
					uni.setStorageSync(this.DATA_KEY.token, '');
					uni.setStorageSync(this.DATA_KEY.etpId, '');
					uni.setStorageSync(this.DATA_KEY.etpName, '');
					uni.setStorageSync(this.DATA_KEY.oldTime, '');
					uni.setStorageSync(this.DATA_KEY.loadingOrderId, '');
					uni.switchTab({
						url: '../index/mine'
					});
				}
			})
		},
		onresve(num) {
			if(num == 1){
				uni.navigateTo({
					url: `../personal/personaldocuments`
				});
			}else{
				uni.navigateTo({
					url: `../personal/driverregistration?isdriverId=true`
				});
			}
		},
		onMyinfo() {
			let driverId = uni.getStorageSync(this.DATA_KEY.userInfo).driverId;
			this.wxRequest({
				url: `${this.API}/driverService/getDriverInfoByDriverID?driver_id=` + driverId + '&etp_id=' + uni.getStorageSync(this.DATA_KEY.etpId),
				method: 'POST',
				title: '加载中...',
				success: res => {
					this.user = res.data.data.userModel;
					uni.setStorageSync(this.DATA_KEY.userInfo, res.data.data.userModel);
					this.$nextTick(() => {
						this.textStatus()
					})
					this.islivingcertifi = this.user.livingBodyState == 0 ? '未认证' : '已认证';
					if(this.user.livingBodyState == 0){
						if(this.orderNumber){
							this.saveFaceVerify()
						}
					}
				},
			});
		},
		persondocuments() {
			if(this.statusText === '已驳回'){
				uni.navigateTo({
					url: `../personal/driverregistration?isdriverId=true`
				});
			}else{
				uni.navigateTo({
					url: `../personal/personaldocuments`
				});
			}
		},
		shake() {
			console.log(this.timer,"oooooo")
			
		    if (this.timer) {
		        // clearTimeout(this.timer)
				return
		    }
			this.livingcertification()
		    this.timer = setTimeout(() => {
				console.log(888888)
		    }, 3000)
		},
		saveFaceVerify() {
			this.wxRequest({
				url: `${this.API}/driverService/saveFaceVerifyState`,
				method: 'POST',
				data: {
					driverId: this.user.driverId,
					orderNumber: this.orderNumber,
					platformCoId: this.platformCoId,
					accessToken: this.accessToken
				},
				success: res => {
					console.log(res)
					this.flag = false
					this.islivingcertifi = '已认证';
					this.user.livingBodyState == 1
					this.onMyinfo()
				},
				complete: () => {
					this.flag = false
				}
			});
		},
		livingcertification() {
			if (this.user.livingBodyState == 0) {
				let that = this;
				that.wxRequest({
					url: `${that.API}/driverService/getDriverIdCardInfo`,
					method: 'POST',
					data: {
						driverId: that.user.driverId,
						platformCoNo: uni.getStorageSync(this.DATA_KEY.platformCoNo)
					},
					title: '加载中...',
					success: res => {
						let accessToken = res.data.data.accessToken; //认证令牌
						this.accessToken = accessToken
						let taxNumber = res.data.data.taxNumber; //平台税号
						let realName = res.data.data.driverName;
						let idCard = res.data.data.idcard;
						let idPhotoUp = res.data.data.idcard1Base64;
						let idPhotoDown = res.data.data.idcard2Base64;
						that.wxRequestData({
							url: `${that.API2}/api/face/getFaceQRCode?access_token=` + accessToken,
							method: 'POST',
							title: '加载中...',
							data: {
								companyTaxNumber: taxNumber,
								realName: realName,
								idCard: idCard,
								idPhotoUp: idPhotoUp,
								idPhotoDown: idPhotoDown,
								callbackUrl: `${that.API}/driverService/isLivingBodyState`
							},
							success: res => {
								console.log("===================>2",res);
								if (res.data.code == 0) {
									let orderNumber = res.data.data.orderNumber;
									this.orderNumber = orderNumber
									let that = this
									that.wxRequest({
										url: `${that.API}/driverService/saveFaceVerifyOrderNumber`,
										method: 'POST',
										data: {
											driverId: that.user.driverId,
											orderNumber: orderNumber,
											platformCoId: uni.getStorageSync(this.DATA_KEY.platformCoNo) == '0001' ? '100001' : '100002'
										},
										success: res => {
											// #ifdef APP-PLUS
											uni.showModal({
												title: '提示',
												content: '是否去进行实名认证?跳转进行实名认证后需要重新打开当前APP!',
												success: function(res) {
													if (res.confirm) {
														console.log('用户点击确定');
														that.timer = null
														that.flag = true
														plus.share.getServices(
															function(res) {
																var sweixin = null;
																console.log(res);
																for (var i = 0; i < res.length; i++) {
																	var t = res[i];
																	console.log(t);
																	if (t.id == 'weixin') {
																		sweixin = t;
																	}
																}
																if (sweixin) {
																	console.log('dddd=', 'a=' + sweixin + '=b');
																	sweixin.launchMiniProgram({
																		// id: 'gh_cec8224b00da',
																		id: 'gh_45eec401ff1c',
																		type: 0, //0-正式版 1.测试版，2，体验版
																		path: 'pages/verify/info/index?id=' + orderNumber
																	});
																}
															},
															function(res) {
																console.log(JSON.stringify(res));
															}
														);
													} else if (res.cancel) {
														console.log('用户点击取消');
														that.timer = null
													}
												}
											});
											// #endif
											
											// #ifdef MP-WEIXIN
											uni.showModal({
												title: '提示',
												content: '是否去进行实名认证?',
												success: function(res) {
													if (res.confirm) {
														that.timer = null
														console.log(that.timer)
														
														that.flag = true
														console.log('用户点击确定');
														uni.navigateToMiniProgram({
															// appId: 'wxfd2861dc1c86b3a0',
															appId: 'wxfc1e27e05fdd062b',
															// path: 'pages/verify/info/index?id=' + orderNumber,
															path: 'pages/verify/info/index?id=' + orderNumber,
															envVersion: 'release',
															success(res) {
																console.log('跳转成功');
															},
															fail(res) {
																console.log('跳转失败' + JSON.stringify(res));
															}
														});
													} else if (res.cancel) {
														that.timer = null
														console.log(that.timer)
														console.log('用户点击取消');
													}
												}
											});
											// #endif
										}
									});
								}
							}
						});
					}
				});
			}
		},
		onupdatph() {
			uni.navigateTo({
				url: `../personal/updatoldphone`
			});
		},
		onproctocl(type) {
			uni.navigateTo({
				url: '../personal/proctcol?type=' + type
			});
		}
	},
	onLoad() {
		this.onMyinfo();
	},
	onShow() {
		this.onMyinfo();
		if(this.flag) {
			this.saveFaceVerify()
		}
		console.log('ddddd');
	}
};
</script>

<style lang="scss">
page {
	font-size: 30rpx;
	background: #f9f9f9;
}
.body{
	padding: 24rpx;
	.item{
		background: #fff;
		border-radius: 14rpx;
		margin-bottom: 24rpx;
		overflow: hidden;
	}
}
.row-css {
	display: flex;
	flex-direction: row;
}

.column-css {
	display: flex;
	flex-direction: column;
}

.view-cente {
	background: #ffffff;
	padding: 0 30rpx;
}
.view-cente-cle {
	padding: 25rpx 0;
	border-bottom: 1rpx solid #eeeeee;
	justify-content: space-between;
}
.view-cente-cle-text {
	width: 180rpx;
	color: #5f6579;
}
.perfection {
	border-radius: 25rpx;
	padding: 5rpx 10rpx;
	color: #ffffff;
}

.position-fixed {
	background: #ffffff;
	display: flex;
	position: fixed;
	bottom: 50rpx;
	justify-content: center;
	border: 1rpx solid #007aff;
	border-radius: 10rpx;
	color: #007aff;
	padding: 20rpx;
	margin: 40rpx;
	width: 84%;
	font-size: 30rpx;
}
.jumpCss{
	width: 300rpx;
	height: 60rpx;
	position: absolute;
	// background: #007aff;
	right: 40rpx;
}
</style>
